@extends('layouts.admin')

@section('title', '系统资源管理')

@section('style')
    <link rel="stylesheet" type="text/css" href="{{asset('lib/jquery.treeTable/themes/vsStyle/treeTable.min.css')}}" />
@endsection

@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 平台 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 系统资源 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <table id="treeTable" class="table table-border table-bordered table-striped table-hover">
            <tr><th>资源名称</th><th>权限标识</th><th>备注</th><th>操作</th></tr>
            @foreach($tree_list as $list)
                <tr id="{{$list['id']}}" pId="{{$list['parent_id']}}">
                    <td class="f-14">{{$list['display_name']}}</td>
                    <td class="f-14">{{$list['name']}}</td>
                    <td class="f-14">{{$list['description']}}</td>
                    <td class="f-14">
                        <a title="添加下级资源" href="javascript:;" data-id="{{$list['id']}}" class="ml-5 addBtn" style="text-decoration:none"><i class="Hui-iconfont">&#xe600;</i></a>
                        @if($list['id']!=1)
                            <a title="编辑" href="javascript:;" data-id="{{$list['id']}}" class="ml-5 editBtn" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            @if(!isset($list['_child']))
                                <a title="删除" href="javascript:;" data-id="{{$list['id']}}" class="ml-5 delBtn" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                            @endif
                        @endif
                    </td>
                </tr>
            @endforeach
        </table>
    </div>
@endsection
@section('script')
    <script type="text/javascript" src="{{asset('lib/jquery.treeTable/jquery.treeTable.min.js')}}"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#treeTable").treeTable({expandLevel : 3});
        });
    </script>
    <script type="text/javascript">
        $(document).on("click",".addBtn",function(){
            layer_show("添加系统资源",'{{url('system/permission/add')}}?parent_id='+$(this).data("id"),800,400);
        });
        $(document).on("click",".editBtn",function(){
            layer_show("编辑系统资源",'{{url('system/permission/edit')}}?id='+$(this).data("id"),800,400);
        });
        $(document).on("click",".delBtn",function(){
            var id=$(this).data("id");
            layer.confirm('确定要删除选择的系统资源？',{
                    btn: ['确定','取消'],
                    shade: false,
                    closeBtn: 0
                },
                function(){
                    $.ajax({
                        url: "{{url('system/permission/delete')}}",
                        data:{id:id},
                        dataType: 'json',
                        success: function(data){
                            if(data['successFlag']==1){
                                layer_success_message('删除成功!');
                                window.location.reload();
                            }
                        },
                        error:function(data) {
                            layer_error_message('删除失败!');
                        },
                    });
                });
        });
    </script>
@endsection